package com.gin.kotlin.no_gay_alliance.fragment.post

import android.os.Bundle
import com.gin.kotlin.no_gay_alliance.adapter.post.UploadedAttachmentAdapter
import com.gin.kotlin.no_gay_alliance.argument.AttachmentArgument
import com.gin.kotlin.no_gay_alliance.base.AbstractBindingFragment
import com.gin.kotlin.no_gay_alliance.databinding.FragmentPostAttachmentManagerBinding

class PostAttachmentManagerFragment : AbstractBindingFragment<FragmentPostAttachmentManagerBinding>() {
    private lateinit var adapter: UploadedAttachmentAdapter
    private lateinit var attachmentArgument: AttachmentArgument
    override fun onCreateView() {

        this.adapter = UploadedAttachmentAdapter(requireContext(), handler!!, this.attachmentArgument.attachments?.toMutableList() ?: mutableListOf())
        this.adapter.attachmentArgument = this.attachmentArgument

        b?.recyclerView?.adapter = this.adapter
    }

    override fun handleArguments(bundle: Bundle) {
        super.handleArguments(bundle)
        this.attachmentArgument = parseBundle(bundle, AttachmentArgument::class.java.simpleName, AttachmentArgument::class.java)
    }

    companion object {
        fun newInstance(attachmentArgument: AttachmentArgument) =
            PostAttachmentManagerFragment().also { it.arguments = Bundle().also { b -> b.putParcelable(AttachmentArgument::class.java.simpleName, attachmentArgument) } }
    }
}